package ControllerSrevlet;

import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import MYJDBC.jdbc;

/**
 * Servlet implementation class User_Video_Text
 */
@WebServlet("/User_Video_Text")
public class User_Video_Text extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public User_Video_Text() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("UTF-8");
		String videotext = request.getParameter("VideoPl");
		String userid = request.getParameter("userid");
		String videoid = request.getParameter("videoid");
		
		int UserId = Integer.parseInt(userid);
		int VideoId = Integer.parseInt(videoid);
		
		Date dd=new Date();
		SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd HH:mm");
		String time=sim.format(dd);
		
		jdbc jc = new jdbc();
		try {
			jc.SqlUpdate("insert into videouser_text (videoid,user_id,videousertext,videousertextitme) value ("+VideoId+","+UserId+",'"+videotext+"','"+time+"')");
			jc.UpdateClose();
			response.sendRedirect("BlueVideoPlay?VideoID="+VideoId+"");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		
		
	}

}
